Use concrete error types for ipld/* and shared#463
Use concrete error types for ipld/* and shared#463dignifiedquire wants to merge 7 commits intomasterfrom
Conversation
fvm/src/blockstore/buffered.rs
Outdated
| #[error("cbor input was not canonical (lval 24 with value < 24)")] | ||
| HeaderLval24, | ||
| #[error("cbor input was not canonical (lval 25 with value <= MaxUint8)")] | ||
| HeaderLval25, | ||
| #[error("cbor input was not canonical (lval 26 with value <= MaxUint16)")] | ||
| HeaderLval26, | ||
| #[error("cbor input was not canonical (lval 27 with value <= MaxUint32)")] | ||
| HeaderLval27, |
There was a problem hiding this comment.
Without knowing what they are really about, I'd collapse them into HeaderLval(u8).
There was a problem hiding this comment.
Probably, I am deferring to figuring out the best thing to @raulk or @Stebalien (not sure who wrote this code)
|
We switched to anyhow because:
|
|
@Stebalien well I would argue they are very useful, because you don't need to downcast anymore, you can actually do type level checks in actors with this |
Sorry, I should have been specific. I meant having many detailed errors rather than just a simple "here's what went wrong" error message. On the other hand, they don't doesn't really hurt, I guess. But please propagate before merging here. I agree with you in theory, but enumerated errors became a real pain in practice.
On the other hand, we started with an unholy mix of enumerated errors, string errors, and anyhow. You may have better luck now. |
anorth
left a comment
There was a problem hiding this comment.
Looks great to me, but please wait for someone else's review too.
ipld/amt/Cargo.toml
Outdated
| once_cell = "1.5" | ||
| ahash = { version = "0.7", optional = true } | ||
| itertools = "0.10" | ||
| anyhow = "1.0.51" |
ipld/amt/src/amt.rs
Outdated
| let found = self.delete(i)?.is_none(); | ||
| if strict && found { | ||
| return Err(anyhow!("no such index {} in Amt for batch delete", i).into()); | ||
| return Err(Error::BatchDelteNotFound(i)); |
| Self::Dynamic(anyhow::anyhow!(e)) | ||
| } | ||
| #[derive(Debug, Error)] | ||
| pub enum EitherError<U, E> { |
There was a problem hiding this comment.
Please add some comments explaining this. I get that it's unioning two types of errors, but don't understand why or how it should be used. What's the distinction between the two types of errors? If raising, how do I chose which one? If handling, what can I infer from the different types?
There was a problem hiding this comment.
added some docs
ipld/amt/src/error.rs
Outdated
| #[error("user: {0}")] | ||
| User(U), | ||
| #[error("hamt: {0}")] | ||
| Hamt(#[from] Error<E>), |
There was a problem hiding this comment.
that’s what I get for copy pasting 😬
|
once the exit code PR lands on builtin-actors, I will make a matchinh PR, to make sure things work as intended based on this. |
| #[error("string in cbor input too long")] | ||
| StringTooLong, | ||
| #[error("Invalid link ({0}) in flushing buffered store")] | ||
| InvalidLink(Cid), |
| } | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum FlushError { |
There was a problem hiding this comment.
I'd reduce this to:
- MissingBlock (can't find a block)
- IPLD (encoding error)
(how can we even have an IO error that's not a blockstore error?)
If we're super-specific, we'll have to break this error type every time we change some detail (switch to libipld's link enumeration function, support new IPLD codecs, etc.).
ipld/blockstore/src/lib.rs
Outdated
| /// | ||
| /// The cgo blockstore adapter implements this trait. | ||
| pub trait Blockstore { | ||
| type Error: std::error::Error + std::fmt::Debug + Send + Sync + 'static; |
There was a problem hiding this comment.
This is what we started with, but it was a huge pain.
- This is incompatible with anyhow, because anyhow doesn't implement
std::error::Error. - Repeating this kind of constraint wherever we want to be generic is really annoying.
What if we just don't constrain this? Really, only applications care about enforcing constraints on this type.
There was a problem hiding this comment.
That is true, the main reason I constrained it is because anyhow::Context requires this, and so it gets painful there, as I can't easily define a where clause on Machine::Blockstore::Error without having to write it in a LOT of places.
There was a problem hiding this comment.
Yeah, I guess that's fine. We just need to make sure we have patches for the actors before we merge.
| /// Internal method to cleanup children, to ensure consistent tree representation | ||
| /// after deletes. | ||
| pub(crate) fn clean(&mut self) -> Result<(), Error> { | ||
| pub(crate) fn clean<BS: Blockstore>(&mut self) -> Result<(), Error<BS::Error>> { |
There was a problem hiding this comment.
Can you use ! or convert::Infallable as the blockstore error?
There was a problem hiding this comment.
If I do that, the error propagation stops working when I call it. If you have an idea how to work around it, I am all ears
d738cb2 to
cd07afe
Compare
ad2998a to
c1f1026
Compare
c1f1026 to
8a68e6a
Compare
8a68e6a to
4b20a04
Compare
|
@Stebalien This is assigned to M2.1 now. Is it correct? |
|
It probably won't land in M2.1. I'd like it to, but I expect we'll handle this in M2.2. |
This is the first step to be able to remove the usage of downcasting in actors.
It removes the usage of anyhow in lower level parts.